package com.zzyl.task;


import cn.hutool.core.date.LocalDateTimeUtil;
import com.zzyl.entity.Reservation;
import com.zzyl.mapper.CustomerReservationMapper;
import com.zzyl.service.CustomerReservationService;
import com.zzyl.utils.UserThreadLocal;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;


@Slf4j
@Component
public class StatusTask {

    @Autowired
    private CustomerReservationMapper customerReservationMapper;


    @Scheduled(cron = "0/5 * * * * ?")
    public void executeTask() {
        List<Reservation> reservation = customerReservationMapper.getReservationAll();
        for (Reservation res : reservation) {
            if (res.getStatus() == 0) {
                if (res.getTime().isBefore(LocalDateTimeUtil.beginOfDay(LocalDateTime.now()))) {
                    customerReservationMapper.updateReservationStatus(res.getId());
                }
            }
        }


    }

}
